package com.mriassl.stream.web;

import java.util.List;

import javax.websocket.Session;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mriassl.stream.service.LotteryService;
import com.mriassl.stream.web.wsocket.IndexServer;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private LotteryService lotteryService;
    
	@RequestMapping("/save/{betno}")
	public String save(@PathVariable("betno")String betno){
	    lotteryService.saveBettingOrder(betno);
		return "保存成功";
	}

	@RequestMapping("/send/{uid}/{msg}")
	public String send(@PathVariable("uid")String uid, @PathVariable("msg")String msg){
	    List<Session> sessions = IndexServer.getSession(uid);
	    sessions.parallelStream().forEach(s -> s.getAsyncRemote().sendText(msg));
	    return "发送成功:"+System.currentTimeMillis();
	}

}
